// pages/user-information/user-information.ts
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    name: "、、、",
    sex: 0,
    grade: "初三（1）班",
    subject: "美术",
    sexGroup: [
      { id: 0, name: "男" },
      { id: 1, name: "女" },
    ],
    subjectGroup: [
      { id: 0, name: "美术" },
      { id: 1, name: "物理" },
      { id: 2, name: "数学" },
      { id: 3, name: "语文" },
    ],
    gradeGroup: [
      { id: 0, name: "初三（1）班" },
      { id: 1, name: "初三（2）班" },
      { id: 2, name: "初三（3）班" },
      { id: 3, name: "初三（4）班" },
    ],
    studentId: '222222',
    isShowSexModal: false,
    isShowNameModal: false,
    isShowGradeModal: false,
    isShowSubjectModal: false,
  },
  handleAvatar(e: any) {
    const { avatarUrl } = e.detail;
    this.setData({
      userInfo: {
        ...this.data.userInfo,
        avatarUrl: avatarUrl,
      }
    })
    // 处理选择头像的逻辑
  },
  handleNameModal() {
    this.setData({
      isShowNameModal: true
    })
  },
  handleSexModal() {
    this.setData({
      isShowSexModal: true
    })
  },
  handleSubjectModal() {
    this.setData({
      isShowSubjectModal: true
    })
  },
  handleGradeModal() {
    this.setData({
      isShowGradeModal: true
    })
  },
  handleCancle() {
    this.setData({
      isShowNameModal: false,
      isShowGradeModal: false,
      isShowSubjectModal: false,
      isShowSexModal: false,
    })
  },
  handleGradeConfirm(e: any) {
    const { name, id } = e.detail
    this.setData({
      grade: name,
      isShowGradeModal: false,
    })
  },
  handleSexConfirm(e: any) {
    const { data } = e.detail
    this.setData({
      sex: data,
      isShowSexModal: false,
    })
  },
  handleSubjectConfirm(e: any) {
    const { name, id } = e.detail
    this.setData({
      subject: name,
      isShowSubjectModal: false,
    })
  },
  handleNameConfirm(e: any) {
    const { data } = e.detail
    if (data.length >= 2 && data.length <= 20) {
      this.setData({
        isShowNameModal: false,
        name: data
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})